﻿using System;
using System.Diagnostics;

namespace HslCommunication.ModBus
{
	/// <summary>
	/// 服务器端提供的数据监视服务
	/// </summary>
	// Token: 0x020000CE RID: 206
	public class ModBusMonitorAddress
	{
		/// <summary>
		/// 本次数据监视的地址
		/// </summary>
		// Token: 0x17000242 RID: 578
		// (get) Token: 0x06000F70 RID: 3952 RVA: 0x0005A892 File Offset: 0x00058A92
		// (set) Token: 0x06000F71 RID: 3953 RVA: 0x0005A89A File Offset: 0x00058A9A
		public ushort Address { get; set; }

		/// <summary>
		/// 数据写入时触发的事件
		/// </summary>
		// Token: 0x1400001B RID: 27
		// (add) Token: 0x06000F72 RID: 3954 RVA: 0x0005A8A4 File Offset: 0x00058AA4
		// (remove) Token: 0x06000F73 RID: 3955 RVA: 0x0005A8DC File Offset: 0x00058ADC
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public event Action<ModBusMonitorAddress, short> OnWrite;

		/// <summary>
		/// 数据改变时触发的事件
		/// </summary>
		// Token: 0x1400001C RID: 28
		// (add) Token: 0x06000F74 RID: 3956 RVA: 0x0005A914 File Offset: 0x00058B14
		// (remove) Token: 0x06000F75 RID: 3957 RVA: 0x0005A94C File Offset: 0x00058B4C
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public event Action<ModBusMonitorAddress, short, short> OnChange;

		/// <summary>
		/// 强制设置触发事件
		/// </summary>
		/// <param name="value">数据值信息</param>
		// Token: 0x06000F76 RID: 3958 RVA: 0x0005A981 File Offset: 0x00058B81
		public void SetValue(short value)
		{
			Action<ModBusMonitorAddress, short> onWrite = this.OnWrite;
			if (onWrite != null)
			{
				onWrite(this, value);
			}
		}

		/// <summary>
		/// 强制设置触发值变更事件
		/// </summary>
		/// <param name="before">变更前的值</param>
		/// <param name="after">变更后的值</param>
		// Token: 0x06000F77 RID: 3959 RVA: 0x0005A998 File Offset: 0x00058B98
		public void SetChangeValue(short before, short after)
		{
			bool flag = before != after;
			if (flag)
			{
				Action<ModBusMonitorAddress, short, short> onChange = this.OnChange;
				if (onChange != null)
				{
					onChange(this, before, after);
				}
			}
		}
	}
}
